/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Service;

import java.util.List;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;
import org.hibernate.Criteria;
import DB.HibernateUtil;
import DB.LLamadaTelefonica;

/**
 *
 * @author Franzel
 */
@WebService()
public class LLamadaTelefonicaWS {
    @WebMethod(operationName = "agregarLLamadaTelefonica")
    public boolean agregarLLamadaTelefonica(@WebParam(name = "LLamadaTelefonica")LLamadaTelefonica llamada) {

        return ControladorDeObjetos.saveObject(llamada);
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "listarLLamadaTelefonicas")
    public List<LLamadaTelefonica> listarLLamadaTelefonicas() {
        //TODO write your implementation code here:
        return ControladorDeObjetos.getAllObjectByClassType(LLamadaTelefonica.class);
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "cargarLLamadaTelefonica")
    public Object cargarLLamadaTelefonica(@WebParam(name = "id") Long id) {
        //TODO write your implementation code here:
        return ControladorDeObjetos.loadObjectByLongId(id, LLamadaTelefonica.class);
    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "modificarLLamadaTelefonica")
    public boolean modificarLLamadaTelefonica(@WebParam(name = "LLamadaTelefonica") LLamadaTelefonica llamada) {
        return ControladorDeObjetos.updateObject(llamada);
    }

    @WebMethod(operationName = "filtrarLLamadasTelefonicas")
    public List<LLamadaTelefonica> filtrarLLamadasTelefonicas(@WebParam(name = "buscar") String buscar) {
        Session s = HibernateUtil.getSessionFactory().getCurrentSession();
        Transaction trans = s.beginTransaction();
        Criteria c = s.createCriteria(LLamadaTelefonica.class).add(Restrictions.or(Restrictions.or(Restrictions.or(Restrictions.like("rutProfesional", "%" + buscar + "%"),
                Restrictions.like("rutPaciente", "%" + buscar + "%")),
                Restrictions.or(Restrictions.like("fecha", "%" + buscar + "%"),
                Restrictions.like("hora", "%" + buscar + "%"))),
                (Restrictions.like("costo", "%" + buscar + "%"))));
        List l = c.list();
        s.close();
        return l;
    }

}
